function ListNode(val) {
    this.val = val;
    this.next = null;
}
var reversePrint = function(head) {
    let p = head
    let n = 0
    while (p != null) {
        p = p.next
        n++
    }
    let arr = []
    let q = head
    for (let i = 0 ; i< n; i++) {
        arr [n- i - 1] = q.val
        q = q.next
    }
    return arr
};
var reversePrint = function(head) {
    let arr = []

    function reverse(head) {
        if (head == null || head.next == null) return head

        let newHead = reverse(head.next)
        head.next.next = head
        head.next = null

        return newHead
    }

    let p = reverse(head)
    while (p != null) {
        arr.push(p.val)
        p = p.next
    }
    return arr
}
let head = new ListNode(1)
head.next = new ListNode(2)
head.next.next = new ListNode(3)
console.log(reversePrint(head))
